package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.service.AdminService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Reference
    private AdminService adminService;

    @RequestMapping("/update")
    public Result udate(@RequestBody Map map, String name) {

        try {
            adminService.update(map, name);
            return new Result(true, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.toString());
            if (e.toString().equals("java.lang.RuntimeException: 密码不一致")){
                return new Result(false, "密码不一致");
            }else {
                return new Result(false, "旧密码错误，请重新输入");
            }


        }
    }


}
